package com.zxl.live.screen.call.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import com.zxl.live.screen.R;
import com.zxl.live.screen.call.helper.NotificationPermissionGuide;
import com.zxl.live.screen.call.tools.CallUtils;
import com.zxl.live.tools.base.BaseAppCompatActivity;
import com.zxl.live.tools.track.StatisticsConstant;
import com.zxl.live.tools.track.StatisticsType;

/**
 * Created by Administrator on 2017/12/11.
 */

public class NotificationAccessGuideAlertActivity extends BaseAppCompatActivity implements View.OnClickListener {

    private NotificationPermissionGuide mNotificationPermissionGuide;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_notification_access_guide_alert_without_icon);
        if (Build.VERSION.SDK_INT >= 19) {
            getWindow().addFlags(67108864);
            getWindow().addFlags(134217728);
        }
        findViewById(R.id.close).setOnClickListener(this);
        findViewById(R.id.enable_btn).setOnClickListener(this);
        mNotificationPermissionGuide = new NotificationPermissionGuide(this, getClass());
    }

    public static void startGuideAlertPage(Context context) {
        if (Build.VERSION_CODES.LOLLIPOP <= Build.VERSION.SDK_INT) {
            if (!CallUtils.hasMediaSessionPermission()) {
                context.startActivity(new Intent(context, NotificationAccessGuideAlertActivity.class));
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mNotificationPermissionGuide.stopMonitor();
        if (mNotificationPermissionGuide.havePermission()) {
            StatisticsType.CALL_FLASH.upload(this, StatisticsConstant.Event.STATUS, "click_notification_set_success");
            finish();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.enable_btn:
                mNotificationPermissionGuide.startMonitor();
                StatisticsType.CALL_FLASH.upload(this, StatisticsConstant.Event.STATUS, "click_notification_set");
                break;
            default:
                finish();
                StatisticsType.CALL_FLASH.upload(this, StatisticsConstant.Event.STATUS, "click_notification_close");
                break;
        }
    }
}
